<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="制令单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['commandbillCode',validatorRules.commandbillCode]" placeholder="请输入制令单号"></a-input>
        </a-form-item>
        <a-form-item label="客户编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['customerCode',validatorRules.customerCode]" placeholder="请输入客户编码"></a-input>
        </a-form-item>
        <a-form-item label="集研编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['researchCode',validatorRules.researchCode]" placeholder="请输入集研编码"></a-input>
        </a-form-item>
        <a-form-item label="测试工位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['testStation',validatorRules.testStation]" placeholder="请输入测试工位"></a-input>
          <!--          <j-multi-select-tag type="checkbox" v-decorator="['testStation']" :trigger-change="true" dictCode="test_station" placeholder="请选择测试工位"/>-->
        </a-form-item>
        <a-form-item label="测试人员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['firstTestPersonnel',validatorRules.firstTestPersonnel]" placeholder="请输入测试人员"></a-input>
        </a-form-item>
        <a-form-item label="对应条码(S)" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['correspondingBarcode',validatorRules.correspondingBarcode]" placeholder="请输入对应条码(S)"></a-input>
        </a-form-item>
        <a-form-item label="不合格现象" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['unqualifiedPhenomenon',validatorRules.unqualifiedPhenomenon]" rows="4" placeholder="请输入不合格现象"/>
        </a-form-item>
        <!--        <a-form-item label="发生日期" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <j-date placeholder="请选择发生日期" v-decorator="['happenDate']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="不合格原因" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-textarea v-decorator="['unqualifiedReason']" rows="4" placeholder="请输入不合格原因"/>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="维修方案" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-textarea v-decorator="['repairProgramme']" rows="4" placeholder="请输入维修方案"/>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="维修人员" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input v-decorator="['repairPersonnel']" placeholder="请输入维修人员"></a-input>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="维修完成后在测试结果" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-textarea v-decorator="['retestResults']" rows="4" placeholder="请输入维修完成后在测试结果"/>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="测试人员" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input v-decorator="['retestPersonnel']" placeholder="请输入测试人员"></a-input>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="确认人员" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input v-decorator="['confirmationPersonnel']" placeholder="请输入确认人员"></a-input>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <j-dict-select-tag type="list" v-decorator="['status']" :trigger-change="true" dictCode="unqualified_repair_card" placeholder="请选择状态"/>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="制令单号" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input v-decorator="['commandbillCode']" placeholder="请输入制令单号"></a-input>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="生产订单ID" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input v-decorator="['produceId']" placeholder="请输入生产订单ID" :disabled="true"></a-input>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <j-dict-select-tag type="list" v-decorator="['type']" :trigger-change="true" dictCode="repair_type" placeholder="请选择类型"/>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="班别" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input v-decorator="['classType']" placeholder="请输入班别"></a-input>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="线别" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input v-decorator="['lineType']" placeholder="请输入线别" :disabled="true"></a-input>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="站别" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-select-->
        <!--            v-model="standType"-->
        <!--            style="width: 100%"-->
        <!--          >-->
        <!--            <a-select-option v-for="(item,index) in typeArray" :key="index">-->
        <!--              {{ item }}-->
        <!--            </a-select-option>-->
        <!--          </a-select>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="机型" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input v-decorator="['model']" placeholder="请输入机型"></a-input>-->
        <!--        </a-form-item>-->
        <!--        <a-form-item label="不良数量" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
        <!--          <a-input-number v-decorator="['badQuantity']" placeholder="请输入不良数量" style="width: 100%"/>-->
        <!--        </a-form-item>-->

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

import { httpAction } from '@/api/manage'
import pick from 'lodash.pick'
import { validateDuplicateValue } from '@/utils/util'
import JDate from '@/components/jeecg/JDate'
import JDictSelectTag from "@/components/dict/JDictSelectTag"
import JMultiSelectTag from "@/components/dict/JMultiSelectTag"


export default {
  name: "ZsUnqualifiedRepairCardModal",
  components: {
    JDate,
    JDictSelectTag,
    JMultiSelectTag,
  },
  data () {
    return {
      commandbillCode:'',
      standType:'',
      form: this.$form.createForm(this),
      title:"操作",
      width:800,
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },
      confirmLoading: false,
      validatorRules: {
        commandbillCode: {
          rules: [
            { required: true, message: '请输入制令单号!'},
          ]
        },
        customerCode: {
          rules: [
            { required: true, message: '请输入客户编码!'},
          ]
        },
        researchCode: {
          rules: [
            { required: true, message: '请输入集研编码!'},
          ]
        },
        testStation: {
          rules: [
            { required: true, message: '请输入制令单号!'},
          ]
        },
        firstTestPersonnel: {
          rules: [
            { required: true, message: '请输入测试人员!'},
          ]
        },
        correspondingBarcode: {
          rules: [
            { required: true, message: '请输入对应条码(S)!'},
          ]
        },
        unqualifiedPhenomenon: {
          rules: [
            { required: true, message: '请输入不合格现象!'},
          ]
        },
      },
      url: {
        add: "/inspect/zsUnqualifiedRepairCard/add",
        edit: "/inspect/zsUnqualifiedRepairCard/edit",
      },
      mesInfo:{},
      typeArray:[],
    }
  },
  created () {
  },
  watch:{
    commandbillCode(newVal,oldVal){
      this.queryInfo()
    }
  },
  methods: {
    queryInfo(){
      this.$http.get('produce/mesCommandbillInfo/queryByCommandBillCode',{
        params:{
          code:this.commandbillCode
        }
      }).then(res => {
        if (res.success) {
          this.mesInfo = res.result
          this.form.setFieldsValue({lineType:this.mesInfo.lineType})
          this.form.setFieldsValue({produceId:this.mesInfo.produceId})
          this.getZhanbie()
        } else {
          this.modal.show({
            type: 'error',
            content: res.data.message
          })
        }
      })
    },
    getZhanbie() {
      this.$http.get('sys/dict/queryDictItemByDictCode',{
        params:{
          dictCode:'stand_by',
          produceGrade:this.mesInfo.produceGrade
        }
      }).then(res => {
        if (res.success) {
          this.typeArray = res.result[0].listValue
        } else {
          this.modal.show({
            type: 'error',
            content: res.data.message
          })
        }
      })
    },
    add () {
      this.edit({});
    },
    edit (record) {
      this.form.resetFields();
      this.model = Object.assign({}, record);
      this.visible = true;
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model,'customerCode','researchCode','testStation','happenDate','unqualifiedPhenomenon','firstTestPersonnel','unqualifiedReason','repairProgramme','repairPersonnel','retestResults','retestPersonnel','correspondingBarcode','confirmationPersonnel','status','commandbillCode','produceId','type','classType','lineType','standType','model','badQuantity'))
      })
    },
    close () {
      this.$emit('close');
      this.visible = false;
    },
    handleOk () {
      const that = this;
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true;
          let httpurl = '';
          let method = '';
          if(!this.model.id){
            httpurl+=this.url.add;
            method = 'post';
          }else{
            httpurl+=this.url.edit;
            method = 'post';
          }
          let formData = Object.assign(this.model, values);
          formData.standType = this.typeArray[this.standType]
          formData.type = 'repair_yzy'
          console.log("表单提交数据",formData)
          httpAction(httpurl,formData,method).then((res)=>{
            if(res.success){
              that.$message.success(res.message);
              that.$emit('ok');
            }else{
              that.$message.warning(res.message);
            }
          }).finally(() => {
            that.confirmLoading = false;
            that.close();
          })
        }

      })
    },
    handleCancel () {
      this.close()
    },
    popupCallback(row){
      this.form.setFieldsValue(pick(row,'customerCode','researchCode','testStation','happenDate','unqualifiedPhenomenon','firstTestPersonnel','unqualifiedReason','repairProgramme','repairPersonnel','retestResults','retestPersonnel','correspondingBarcode','confirmationPersonnel','status','commandbillCode','produceId','type','classType','lineType','standType','model','badQuantity'))
    },


  }
}
</script>